package com.zy.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 在SpringBoot中，只能通过创建SpringMVC配置文件来注册拦截器
 * @author 张宇
 * @date 2021/7/27 17:38
 */
@Configuration
public class FrontsWebMvcConfiguration implements WebMvcConfigurer
{

    @Resource
    private LoginInterceptor loginInterceptor;

    /**
     * 注册自定义拦截器，添加拦截路径和排除拦截路径
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("/getUserMessageOfLogin");//只拦截这个接口
                .excludePathPatterns("/login")//拦截除登录以外的其他接口
                .excludePathPatterns("/captcha")
                .excludePathPatterns("/fronts/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/element/**")
                .excludePathPatterns("/imge/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/layui-v2.5.7/**")
                .excludePathPatterns("/test/**");
    }

}
